/**********************************************************************
*	pay.app.js
* 
* llrock	@ 2017.1.3
***********************************************************************/


redirectUrl("#p-shop");
$(document).ready(function(){ 
 	myApp.init();
});

//--------------------------------------------------------
//			p-login  登录
//--------------------------------------------------------

// PAGE_SHOW2("#p-login",function(){
// 	LOADER_HIDE();
// });
// 登陆按钮
// CLICK("#p-login .submit-button",function(){
// 	var mobile	= $("#p-login input[name=mobile]").val();
// 	var pass	= $("#p-login input[name=password]").val();
// 	LOADER_SHOW();
// 	// apiLogin(mobile,pass);	
// 	apiLoginByToken();
// });


//--------------------------------------------------------
//			p-index
//--------------------------------------------------------
PAGE_INIT("#p-index",function(e){
	LOADER_HIDE();
});




PAGE_SHOW("#p-index",function(e){
	LOADER_HIDE();
	apiLoginData();
});

//--------------------------------------------------------
//			p-myinfo
//--------------------------------------------------------
PAGE_INIT("#p-myInfo",function(e){
	LOADER_HIDE();
	$("#p-myInfo .sub-title").text(GUser["operator"].realName);
	$("#p-myInfo .title").text(GUser["operator"].mobileNo);
});

PAGE_SHOW("#p-myInfo",function(e){
	LOADER_HIDE();
	$("#p-myInfo .sub-title").text(GUser["operator"].realName);
	$("#p-myInfo .title").text(GUser["operator"].mobileNo);
});

CLICK("#p-myInfo .mylogout", function(){
	apiLogout(function(){
		redirectUrl("#p-shop");
	});
});

// --------------------------------------------------------
// 			p-shop
// --------------------------------------------------------

PAGE_SHOW2("#p-shop", function(){	
  shopSelect(); 
	apiListProduct(null, function(data) {	
      shopList(data);

    });
  
  $(document).delegate('.Q-buy-btn','click', function() {   
        addCart();
        // apiListCart(null,function(res) {  //ajax
        //     console.log(res)
        //   });     
       setTimeout("bounce()",500); //动画
      });  

	});
PAGE_SHOW2("#p-commoditydetails", function() { 
  var id = $.getUrlParam('productId');
  var data = {'id':id};
  _TR(data);
  
  findProduct(data, function(res){
    _TR(res.id);
    var html = '<div class="goods_details_title bgbox">'+
                      '<p class="priceone">'+"￥"+res.price+'</p>'+
                      '<p class="pricetwo">'+
                       '<u>'+19+'</u>'+
                       '<u>'+'月售8笔'+'</u>'+'</p>'+
                       '<p class="codebtn_box">'+'<img src="img/writecodeflag.png">'+'</p>'+
                       '<p class="Dbtn_box">'+'<img src="img/3d.png">'+'</p>'+
               '</div>'+
              '<div class="goods_details">'+
                      '<div class="goods_details_top">'+
                        '<p class="goods_details_top_left">'+'<span>'+"\u3010"+res.brandName+"\u3011"+'</span>'+res.name+'</p>'+ 
                        '<p class="goods_details_top_right">'+'<img src="img/add.png" class="addgoodsCart">'+'</p>'+
                      '</div>'+
                      '<div class="goods_details_con">'+res.remark+'</div>'+
              '</div>';    
    $('.shop_product').empty();
    $('#p-commoditydetails .shop_product').append(html); 
    $('.addgoodsCart').on('click', function() {
          addCart2();
          setTimeout("bounce2()",500); 
        });  
    });
});
